package com.atguigu.tingshu.order.config;

import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

/**
 * @author atguigu-mqx
 * @ClassName CanelOrderMqConfig
 * @description: TODO
 * @date 2025年04月24日
 * @version: 1.0
 */
@Configuration
public class CancelOrderMqConfig {

    //  交换机
    @Bean
    public CustomExchange delayExchange(){
        //  创建map 集合;
        HashMap<String, Object> map = new HashMap<>();
        //  设置参数
        map.put("x-delayed-type","direct");
        //  返回交换机;
        return new CustomExchange(MqConst.EXCHANGE_CANCEL_ORDER,"x-delayed-message",true,false,map);
    }

    //  队列
    @Bean
    public Queue dealyQueue(){
        //  创建队列;
        return new Queue(MqConst.QUEUE_CANCEL_ORDER,true,false,false);
    }

    //  绑定关系
    @Bean
    public Binding dealyBinding(){
        //  绑定完成
        return BindingBuilder.bind(dealyQueue()).to(delayExchange()).with(MqConst.ROUTING_CANCEL_ORDER).noargs();
    }
}
